class Solution(object):
    def isAlienSorted(self, words, order):
        """
        :type words: List[str]
        :type order: str
        :rtype: bool
        """
        d = {order[index]: chr(ord('a') + index) for index in range(len(order))}

        def cmp(word):
            s = [d[c] for c in word]
            return ''.join(s)

        words = [cmp(word) for word in words]
        n = len(words)
        for i in range(1, n):
            if words[i] < words[i - 1]:
                return False
        return True


data = Solution()
words = ["hello", "leetcode"]
order = "hlabcdefgijkmnopqrstuvwxyz"
print(data.isAlienSorted(words, order))
words = ["apple", "app"]
order = "abcdefghijklmnopqrstuvwxyz"
print(data.isAlienSorted(words, order))
